package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-12-07
 * Time: 14:14
 */

class MyThread extends Thread {
    @Override
    public void run() {
        //在这个代码中就可以获取线程的引用
        // 直接通过 this 可直接进行引用.
        System.out.println(this.getId() + "," + this.getName());
        /*
        继承与Thread,直接使用 this 拿到线程实例,
        如果是 Runnable 或者 lambda 的方式,this就无能为力了.此时已经不再指向Thread 对象
        就只能使用 Thread.currentThread();方法了
        */
    }
}
public class ThreadDemo15 {

    public static void main(String[] args) throws InterruptedException {
       MyThread t1 = new MyThread();
       MyThread t2 = new MyThread();
       t1.start();
       t2.start();

       Thread.sleep(1000);

        System.out.println(t1.getId() + "," + t1.getName());
        System.out.println(t2.getId() + "," + t2.getName());
    }
}
